Skip to content

Override upload file max size in mb #2370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MuPp3t33r
Copy link

For attention to @bradenmacdonald to review if this PR meets requirements.

Description

This update makes the following changes:
constants.js:

  • Fix incorrect comment for 20MB default file upload limit
  • Retain the default 20MB limit but use an override (if exists) from GetConfig, allowing users to specify an override value via MFE_CONFIG API
  • Validation that the value entered is a valid and positive integer (use default in case something goes horribly wrong)
  • Written as a function allowing it to be called by other components

FilePage.jsx:

  • Remove the hardcoded maxFileSize value and instead import it from constants.js

ModalDropzone.jsx:

  • Removed UPLOAD_FILE_MAX_SIZE constants that were defined and replaced with a call to the new function in constants.js

TextbookForm.jsx:

  • Removed UPLOAD_FILE_MAX_SIZE constants that were defined and replaced with a call to the new function in constants.js

Imports from constants now use the updated new format '@src/constants' instead of the old '../../constants'

Supporting information

this is an improvement to my previous attempt before i really knew what i was doing, now I only know a little bit of what I'm doing :)

Testing instructions

  1. Replace this MFE using a plugin:
from tutormfe.hooks import MFE_APPS

@MFE_APPS.add()
def _override_authoring_mfe(mfes):
    mfes["authoring"] = {
        "repository": "https://github.com/MuPp3t33r/frontend-app-authoring.git",
        "version": "OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB", 
        "port": 2001, 
    }
    return mfes

  1. Rebuild your MFE
  • tutor images build mfe
  1. Apply the patched values to override the config.
    Note that this must be done in MFE_CONFIG and in the CaddyFile to allow Caddy to process your larger requests
    Here is a sample plugin allowing user to provide one input for the value and it applies in both locations
from tutor import hooks

# Instructions / info
# override_value is defined as a string so bad formats (incorrectly entered values) don't crash Python immediately
# User MUST enter only digits as a POSITIVE integer representing a value in MegaBytes (MB), e.g. "1024" for 1GB
# This adds the value to the MFE_Config API as well as the CaddyFile CMS block

override_value = "1024"  

# --- Validation ---
try:
    override_int = int(override_value)
    if override_int <= 0:
        raise ValueError
except ValueError:
    raise ValueError(
        f"Invalid override_value: {override_value}. "
        "It must be a positive integer without units (e.g., 1048)."
    )

# --- Config patches ---
hooks.Filters.ENV_PATCHES.add_items([
    (
        "openedx-lms-production-settings",
        f"""
MFE_CONFIG["OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB"] = "{override_int}"
"""
    ),
])

hooks.Filters.ENV_PATCHES.add_item(
    (
        "caddyfile-cms",
        f"""
# Maximum asset upload size in CMS/Studio
handle /assets/* {{
    request_body {{
        max_size {override_int}MB
    }}
}}
        """
    )
)

  1. Finally - enable the override plugin and restart your instance:
  • tutor plugins enable override_max_asset_upload_size
  • tutor local stop && tutor local start -d

Now, under the following menus:

  • Content -> Files
  • Content -> Pages & Resources -> Textbooks
    You will find that you can upload files up to whatever maximum defined in the override_max_asset_upload_size plugin

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Aug 11, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @MuPp3t33r!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Aug 11, 2025
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Aug 14, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Needs Tests Run or CLA Signed in Contributions Aug 14, 2025
@e0d
Copy link

e0d commented Aug 14, 2025

@MuPp3t33r Thanks for your detailed PR description. I've approved the tests to run here and will await @bradenmacdonald 's review.

@e0d
Copy link

e0d commented Aug 14, 2025

@MuPp3t33r I notice there are some commit-lint failures. Please note that we use conventional commits across Open edX projects. You can read about the details here. Can you please amend your commit messages to follow our standard?

@mphilbrick211 mphilbrick211 moved this from Needs Tests Run or CLA Signed to Waiting on Author in Contributions Aug 14, 2025
@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Aug 14, 2025
@bradenmacdonald
Copy link
Contributor

@MuPp3t33r Thanks for the revised version here, and especially for the nice testing instructions! I will try to review this shortly.

In the meantime, would you mind addressing these minor lint issues? And as @e0d mentioned, we need the commits to start with feat: in order to pass the check. Let me know if you want help with how to do that.

Original configuration had a hard-coded limit of 20MB per file supplied to the platform. 

This change will retain the existing 20MB limit as default, but provide the admin with the ability to override the value via the MFE_CONFIG API (getConfig)

The new function includes validation to check that the override value supplied is in fact a valid and positive integer and reverts to default 20MB in case of validation failure
Originally the constant 'maxFileSize' was hardcoded to 20MB and was not configured to use the pre-existing value defined in constants.js

This fix removes the hardcoded value and calls the function getUploadFileMaxSize() to determine the value of maxFileSize
This change allows the ModalDropzone to fetch the maximum allowed size via a call to getUploadFileMaxSize() defined in constants.
Additionally fixes the conversion factor (maxSize/(1024*1024) vs (1000*1000) for consistency with upstream code
This change allows the TextbookForm to fetch the maximum allowed size via a call to getUploadFileMaxSize() defined in constants.
Additionally fixes the conversion factor (maxSize/(1024*1024) vs (1000*1000) for consistency with upstream code
@MuPp3t33r MuPp3t33r force-pushed the OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB branch from 694830e to 6b60d91 Compare August 18, 2025 13:33
@MuPp3t33r
Copy link
Author

@e0d @bradenmacdonald
Hopefully I've done it right this time and not butchered anything else in the process :)
Would you mind re-running the tests to confirm?

@e0d
Copy link

e0d commented Aug 18, 2025

I've run them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

5 participants